<?php

namespace Model\MessageBundle\Controller;

use Model\MessageBundle\Setting\MessageSetting;
use Model\MessageCategoryBundle\Model\MessageCategoryModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Model\MessageBundle\Entity\Message as Entity;

/**
 * @route("/admin/")
 */
class MessageAdminController extends BaseController
{

    /**
     * @route("Message/add",name="MessagePreAdd")
     */
    public function add()
    {
        //通用代码
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comAdd();
    }

    /**
     * @route("Message/add/do",name="MessageDoAdd")
     *
     * @Method({"GET", "POST"})
     */
    public function doAdd(Request $request)
    {
        //私有代码
        $entity = new Entity();
        $entity->setAddTime(time());

        //通用代码
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comDoAdd($request,$entity);
    }

    /**
     * @route("Message/edit/{id}",name="MessagePreEdit")
     */
    public function edit(Entity $entity)
    {
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comEdit($entity);
    }

    /**
     * @route("Message/edit/{id}/do",name="MessageDoEdit")
     *
     * @Method({"GET", "POST"})
     */
    public function doEdit(Request $request,Entity $entity)
    {
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comDoEdit($request,$entity);
    }

    /**
     * @route("Message",name="MessageLists")
     */
    public function lists()
    {
        //私有部分
        $MessageCategoryModel = new MessageCategoryModel($this->getDoctrine());
        $classes = $MessageCategoryModel->getAllMessageCategoryTree();
        $tools = array("MessageCategory"    => $classes,);

        //通用部分
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comLists($tools);
    }


    /**
     * @route("Message/tools",name="MessageTools")
     */
    public function tools(Request $request)
    {
        $this->setSetting(new MessageSetting($this->getDoctrine()->getManager()));
        return $this->comTools($request);
    }

}
